//
//  CourseSearchResultView.m
//  Arts1
//
//  Created by 孤星晨宇 on 15/10/12.
//  Copyright © 2015年 Arts1. All rights reserved.
//

#import "CourseSearchResultView.h"
#import "CourseModel.h"

@interface CourseSearchResultView ()<UITableViewDataSource,UITableViewDelegate>


@end


@implementation CourseSearchResultView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        _resultView = [[UITableView alloc] initWithFrame:self.bounds style:(UITableViewStylePlain)];
        _resultView.delegate = self;
        _resultView.dataSource = self;
        [self addSubview:_resultView];
    }
    return self;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SearchCourse"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"SearchCourse"];
    }
    CourseModel *model = (CourseModel *)_dataArr[indexPath.row];
    cell.textLabel.text = model.title;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    CourseModel *model = (CourseModel *)_dataArr[indexPath.row];
    if (_coursesearchBlock) {
        _coursesearchBlock(model.Id);
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
